<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>axios学习笔记2</title>
    <script src="axios.js"></script>
</head>
<body>
<script>
  //request 实际就是axios对象本身
  const request = axios.create({
    baseURL: 'http://localhost:8080', // 主机地址,最后面不加 /
    timeout: 1000, // 超时时间 ms, Error: timeout of 10ms exceeded
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      'token': 'haha123'
    }
  })

  request({
    url: '/user/list',
    method: 'get'
  }).then(response => {
    // 注意: 最好拿出 data
    console.log('数据获取成功', response.data)
  }).catch(error => {
    console.log('数据获取失败', error)
  })

  request.get('/user/list')
    .then(response => {
      console.log('数据获取成功', response.data)
    })
    .catch(error => {
      console.log('数据获取失败', error)
    })
</script>
</body>
</html>